package cn.glutnn;

import java.util.Scanner;

import cn.glutnn.console.NoticeConsole;
import cn.glutnn.dao.UserDao;
import cn.glutnn.entity.User;

public class Administrator {

	public static UserDao userDao = new UserDao();
	
	public static NoticeConsole noticeConsole = new NoticeConsole();

	public static void main(String[] args) {
		login();
	}

	/**
	 * 登录功能
	 */
	public static void login() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入用户名：");
		String username = scanner.nextLine();

		System.out.println("请输入密码：");
		String password = scanner.nextLine();

		User user = userDao.findOneByUsernameAndPassword(username, password);

		if (user != null) {
			menu();
		} else {
			System.out.println("登录失败");
			System.out.println("是否结束系统（如果输入quit，那么退出系统）：");
			String input = scanner.nextLine();
			if("quit".equalsIgnoreCase(input)) {
				return;
			} else {
				login();
			}
		}
	}
	
	/**
	 * 显示菜单
	 */
	public static void menu() {
		System.out.println("==== 主菜单 ====");
		System.out.println("1、新增电影");
		System.out.println("2、查询电影");
		System.out.println("3、修改电影");
		System.out.println("4、删除电影");
		System.out.println("-------------");
		
		System.out.println("请选择：");
		Scanner scanner = new Scanner(System.in);
		String select = scanner.nextLine();
		
		if ("1".equals(select)) {
			noticeConsole.save();
		} else if ("2".equals(select)) {
			noticeConsole.search();
		} else if ("3".equals(select)) {
			noticeConsole.update();
		} else if ("4".equals(select)) {
			noticeConsole.delete();
		}
		
		System.out.println("是否结束系统（如果输入quit，那么退出系统）：");
		String input = scanner.nextLine();
		if("quit".equalsIgnoreCase(input)) {
			return;
		} else {
			menu();
		}
	}
}
